package com.ebupt.migu.music.iop.service.impl;

import com.alibaba.fastjson.JSON;
import com.ebupt.migu.common.pojo.IopTag;
import com.ebupt.migu.common.pojo.NullObj;
import com.ebupt.migu.common.response.Response;
import com.ebupt.migu.common.response.ResponseBean;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.iop.service.IopService;
import com.ebupt.migu.restapi.RestHttpPost;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 集团iop标签验证
 * @author tz
 */
@Slf4j
@Service
public class IopServiceImpl implements IopService {

    @Value("${label.prefix}")
    private String prefix;
    @Value("${label.iop_get}")
    private String iopGet;

    @Override
    public ResultObject getTags() {
        RestHttpPost post = new RestHttpPost();
        Response<String> response = post.doRest(new NullObj(), prefix + iopGet);
        if ("0000".equals(response.getHead().getResponseCode())) {
            ResponseBean res = JSON.parseObject(response.getResponse(), ResponseBean.class);
            log.info("code:{},msg:{}", res.getCode(), res.getMsg());
            if (null != res.getData()) {
                List<IopTag> iopTags = JSON.parseArray(JSON.toJSONString(res.getData()), IopTag.class);
                return new ResultObject<>().success("ok",iopTags);
            }
        }
        return null;
    }
}
